import { dateFormat } from '@vimi/utils-tool'
import { enumFourModernType, enumEntProperty } from '@/bigcredit/views/program/enum'

export const enumGuatype = {
  // 提出删除市联担
  2: '直担业务',
  3: '限率业务',
  4: '联担业务',
  5: '总对总业务',
}

export const enumYesOrNo = {
  0: '否',
  1: '是',
}
// 市场化项目台账
export const ledgerTableColumns = [
  { attrs: { label: '序号', prop: 'index', align: 'center', minWidth: 50 } },
  { attrs: { label: '贷款银行', prop: 'bank_name', align: 'center', minWidth: 160 } },
  {
    attrs: { label: '企业名称/贷款人名称', prop: 'customer_name', align: 'center', minWidth: 200 },
    process: (v, row) => ({
      attrs: { class: 'project-history', attrs: { 'data-history': row.is_history } },
    }),
  },
  {
    attrs: {
      label: '担保金额(万元)',
      prop: 'warranty_amount',
      align: 'center',
      minWidth: 140,
      sortable: 'warranty_amount',
    },
  },
  {
    attrs: {
      label: '在保余额(万元)',
      prop: 'left_funds',
      align: 'center',
      minWidth: 140,
      sortable: 'left_funds',
    },
  },
  {
    attrs: {
      label: '担保发生日期',
      prop: 'loadDate',
      align: 'center',
      minWidth: 140,
      sortable: 'load_date',
    },
  },
  {
    attrs: {
      label: '担保解除日期',
      prop: 'loadEndDate',
      align: 'center',
      minWidth: 140,
      sortable: 'load_end_date',
    },
  },
  { attrs: { label: '项目状态', prop: 'loanBehStatus', align: 'center', minWidth: 140 } },

  { attrs: { label: '客户类型', prop: 'org_class_name', align: 'center', minWidth: 160 } },
  { attrs: { label: '企业属性', prop: 'entProperty', align: 'center', minWidth: 100 } },
  { attrs: { label: '四化类型', prop: 'fourModernType', align: 'center', minWidth: 100 } },
  {
    attrs: { label: '十二大产业分类', prop: 'main_business', align: 'center', minWidth: 200 },
    process: v => v || '-',
  },
  {
    attrs: { label: '主营业务', prop: 'parent_main_business', align: 'center', minWidth: 170 },
    process: v => v || '-',
  },
  {
    attrs: {
      label: '导入日期',
      prop: 'create_time',
      align: 'center',
      minWidth: 120,
      sortable: 'create_time',
    },
    process: v => dateFormat(v, 'yyyy-MM-dd'),
  },
  {
    attrs: { label: '营业执照号', prop: 'register_no', align: 'center', minWidth: 140 },
    process: v => v || '-',
  },
  { attrs: { label: '负责人名称', prop: 'corp_name', align: 'center', minWidth: 140 } },
  {
    attrs: { label: '身份证号', prop: 'lender_idcard', align: 'center', minWidth: 140 },
    process: v => v || '-',
  },
  { attrs: { label: '联系电话', prop: 'corp_phone', align: 'center', minWidth: 120 } },

  { attrs: { label: '销售收入(万元)', prop: 'sale_income', align: 'center', minWidth: 120 } },
  { attrs: { label: '资产总额(万元)', prop: 'assets_funds', align: 'center', minWidth: 120 } },
  { attrs: { label: '从业人数(人)', prop: 'emp_total', align: 'center', minWidth: 120 } },

  { attrs: { label: '贷款利率(%)', prop: 'load_rate', align: 'center', minWidth: 100 } },
  {
    attrs: { label: '借款合同号', prop: 'gua_contract', align: 'center', minWidth: 160 },
    process: v => v || '-',
  },
  {
    attrs: { label: '保证合同编号', prop: 'ensure_contract', align: 'center', minWidth: 160 },
    process: v => v || '-',
  },
  {
    attrs: { label: '委托担保合同号', prop: 'entrust_contract', align: 'center', minWidth: 180 },
    process: v => v || '-',
  },

  {
    attrs: {
      label: '贷款期限(月)',
      prop: 'warranty_period',
      align: 'center',
      minWidth: 80,
      sortable: 'warranty_period',
    },
  },
  {
    attrs: { label: '反担保措施(详情)', prop: 'warranty_method', align: 'center', minWidth: 160 },
    slot: 'warranty_method',
  },
  {
    attrs: { label: '风险分担比例', prop: 'risk_rate', align: 'center', minWidth: 100 },
    process: v => v || '-',
  },
  { attrs: { label: '是否为扶贫项目', prop: 'isPovertyProject', align: 'center', minWidth: 120 } },
  { attrs: { label: '综合担保费率(%)', prop: 'warranty_rate', align: 'center', minWidth: 100 } },
  {
    attrs: { label: '综合担保费金额(元)', prop: 'warranty_fee', align: 'center', minWidth: 140 },
    process: v => v || '-',
  },
  {
    attrs: {
      label: '联保机构名称',
      prop: 'recommend_service_name',
      align: 'center',
      minWidth: 160,
    },
  },

  { attrs: { label: '贷款用途', prop: 'funds_use_dir', align: 'center', minWidth: 140 } },
  { attrs: { label: '行业分类', prop: 'industrial_name', align: 'center', minWidth: 140 } },
  { attrs: { label: '业务类型', prop: 'guaType', align: 'center', minWidth: 110 } },
  {
    attrs: { label: '备注', prop: 'remark', minWidth: 180 },
    process: v => v || '-',
  },
]

export const reportDataAdapter = item => {
  item.isPovertyProject = enumYesOrNo[item.is_poverty_project] || '-'
  item.loanBehStatus =
    +item.load_beh_status === 6 ? `解保(${dateFormat(item.un_gua_time, 'yyyy-MM-dd')})` : '在保'

  item.loadDate = dateFormat(item.load_date, 'yyyy-MM-dd')
  item.loadEndDate = dateFormat(item.load_end_date, 'yyyy-MM-dd')
  item.fourModernType = enumFourModernType[item.four_modern_type]
  item.entProperty = enumEntProperty[item.ent_property]
  item.guaType = enumGuatype[item.gua_type]

  return item
}
